<?php

namespace App\Hospital\Controllers;

use App\Http\Controllers\Controller;
use App\Jobs\AppointList;
use App\Models\Appoint;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class AppointApiController extends Controller
{
    public function queue(Request $request){
        if(!$request->input('id')){
            return new JsonResponse(['code'=>500,'msg'=>'失败，id参数不正确'],500);
        }
        $id = $request->input('id');
        $appoint = Appoint::query()->where('id',$id)->first();
        if(!$appoint){
            return new JsonResponse(['code'=>500,'msg'=>'失败，id不存在'],500);
        }
        try {
            AppointList::dispatch($appoint);
            return new JsonResponse(['code'=>200,'msg'=>'成功'],200);
        }catch (\Exception $exception){
            return new JsonResponse(['code'=>500,'msg'=>$exception->getMessage()],500);
        }
    }

}
